// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// w [author] rhyme_lph
// E [email]  rhymelph@gmail.com
// h [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/entities/business_contact_entity.dart';
import 'package:finance_app/src/provider/dashboard/contact/statement_of_account_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';
import 'package:finance_app/src/widgets/button/normal_text_button.dart';
import 'package:finance_app/src/widgets/common_app_bar.dart';
import 'package:finance_app/src/widgets/form/text_area_input_form.dart';
import 'package:flutter/material.dart';

@RouterMeta(paramName: "statementOfAccountPage")
class StatementOfAccountPage extends StatefulWidget {
  final BusinessContactEntity data;

  const StatementOfAccountPage({Key key, this.data}) : super(key: key);

  @override
  _StatementOfAccountPageState createState() => _StatementOfAccountPageState();
}

class _StatementOfAccountPageState extends State<StatementOfAccountPage>
    with PagePresenter<StatementOfAccountPage, StatementOfAccountProvider> {
  String get title => S.current.statement_of_account;

  Widget _buildNextBtn() {
    return listBuilder<bool>(
      selector: (_, __) => pageStatus != PageStatus.loading,
      builder: (BuildContext context, bool value, Widget child) => value == true
          ? NormalNextTextButton(
              onTap: provider.onNext,
            )
          : Container(),
    );
  }

  @override
  PreferredSizeWidget get appBar =>
      getDefaultAppBar(titleWidget: Text(title), actions: [
        _buildNextBtn(),
      ]);

  @override
  void initState() {
    if (widget.data != null) {
      provider.contact = widget.data;
      print("providerbusinessContact: ${provider.contact}");
    }
    super.initState();
  }

  @override
  Widget get buildWidget => ColoredBox(
        color: Colors.white,
        child: ListView(
          children: [
            TextAreaInputForm(
              title: S.current.payment_instructions,
              controller: provider.instructionsController,
              focusNode: provider.instructionsFocusNode,
            ),
            TextAreaInputForm(
              title: S.current.additional_notes,
              controller: provider.noteController,
              focusNode: provider.noteFocusNode,
            ),
          ],
        ),
      );
}
